package al.xc.common.util;

import java.util.Date;
import java.util.Random;

/**
 * 随机数
 */
public class RandomUtils {
    /**
     * 全局变量
     */
    private static final Random global_ = new Random(new Date().getTime());
    /**
     * 线程本地变量
     */
    private static SelfThreadLocal<Random> local_ = new SelfThreadLocal<>(()-> new Random(global_.nextLong()));

    /**
     * 下一个随机数
     * @param min
     * @param max
     * @return
     */
    public static int next(int min, int max) {
        return (Math.abs(local_.get().nextInt()) % (max + 1 - min)) + min;
    }
}
